/*
 * Created by SharpDevelop.
 * User: rseward
 * Date: 6/4/2008
 * Time: 5:54 AM
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */

using System;
using System.Text;

namespace AvvaMobileNHibernateHelperKit
{
	/// <summary>
	/// Utilities for formatting / translating column_name to class / property names.
	/// </summary>
	public class NameUtils
	{
		public static string GetPropertyName( string tableName, string colName)
		{
			string propName = colName;
			if (tableName.Equals(colName)) {
				propName += "_";
			}
			
			return propName;
		}
		
		/// <summary>
		/// This method changes an underscore name into Camel Case Identifier
		/// </summary>
		/// <param name="name"></param>
		/// <returns></returns>
		public static string CamelifyName( string name )
		{
			StringBuilder camelName = new StringBuilder( name.Length );
			
			bool upcase=false;
			for (int idx=0; idx< name.Length; idx++) {
				if (name[idx]=='_' || name[idx]==' ' || name[idx]=='-' ) {
					upcase=true;
					// skip this char and upcase the next
				} else {
					char c = name[idx];
					if (upcase) {
						c = Char.ToUpper( c );
					}
					upcase=false;
					
					camelName.Append( c );
				}
			}
			
			return ""+camelName;
		}
		
		public static string Uncapitalize(string name)
		{
			if (name.Length>1) {
				StringBuilder newName = new StringBuilder( name.Length );
				char c = name[0];
				
				newName.Append( Char.ToLower( c ) );
				newName.Append( name.Substring(1) );
				
				return ""+newName;
			} 
				
			return name;
		}
		
		public static string Capitalize(string name)
		{
			if (name.Length>1) {
				StringBuilder newName = new StringBuilder( name.Length );
				char c = name[0];
				
				newName.Append( Char.ToUpper( c ) );
				newName.Append( name.Substring(1) );
				
				return ""+newName;
			} 
				
			return name;			
		}
		
		
		
		
		
		
	}
}
